#!/usr/bin/env python3

import sys, time
import threading
import binascii
import Queue
import json
import RPIO
import nnpy

        
class Drive(object):
    """docstring for Drive"""
    local_url = "ipc:///tmp/drive.ipc"
    web_url = "ipc:///tmp/web.ipc"
    remote_urls = [web_url]

    def __init__(self):
        super(Device, self).__init__()
        self.ipc_sock = nnpy.Socket(nnpy.AF_SP, nnpy.BUS)
        self.ipc_sock.bind(local_url)
        for url in self.remote_urls:
            self.ipc_sock.connect(url)

        time.sleep(1)
        sock.setsockopt(nnpy.SOL_SOCKET, nnpy.RCVTIMEO, 1500)
        print("Device ipc ready.")

    def proc_msg(self):
        while True:
            try:
                msg = self.ipc_sock.recv()
                print(f"[Device] recv: {msg}")
            except nnpy.errors.NNError, e:
                print(e)
                break

    def proc_msg_thread_run(self):
        thread_drive = threading.Thread(target=self.msg_output_proc)
        thread_drive.setDaemon(True)
        thread_drive.start()
